<template>
  <div class="bg-fff h-100p bdr-10 pd-10">
    <v-plain-table :native="{stripe:true}" :data="salesmen" @change="change">
      <template slot="expand" slot-scope="{scope}">
        <!-- <el-button type="text">审核</el-button> -->
        <el-button type="text" @click="$router.push(`/platform/member/detail/${scope.row.id}`)">
          详情
        </el-button>
      </template>
    </v-plain-table>
  </div>
</template>
<script lang="ts">

  import { Component, Vue } from 'vue-property-decorator'
  import vPlainTable from '@/components/plain-table'
  import vPanelTop from '@/components/pannel-top'

  @Component({
    components: {
      vPlainTable, vPanelTop
    }
  })
  export default class salesmen extends Vue {
    salesmen: TableData = {
      header: [
        {
          label: '账号',
          key: 'username'
        },
        {
          label: 'id',
          key: 'id'
        },
        {
          label: '姓名',
          key: 'realName'
        },
        {
          label: '联系方式',
          key: 'contactInformation'
        },
        {
          label: '创建日期',
          key: 'createTime',
          formatter: row => this.$utils.toTimeFormat(row.createTime)
        },
        {
          label: '最后登录',
          key: 'date',
          formatter: row => this.$utils.toTimeFormat(row.lastLoginTime)
        }
      ],
      body: [],
      footer: {
        total: 0,
        currentPage: 1
      }
    }
    userId = ''
    url = 'g/gateway/channelprovider/salesman/list'
    change (page) {
      this.salesmen.footer.currentPage = page
      this.getSalesmen()
    }

    async getSalesmen () {
      let res: AjaxResponse = await this.$axios.post(this.url, {
        pageSize: 10,
        currentPage: this.salesmen.footer.currentPage,
        userId: this.$route.params.id || this.userId
      })
      this.salesmen.body = res.data.items
      this.salesmen.footer.total = res.data.totalNum
      this.salesmen.footer.currentPage = res.data.currentPage
    }

    mounted () {
      let userInfo = JSON.parse(window.sessionStorage.getItem('userInfo'))
      this.userId = userInfo.userId
      if (userInfo.roleType === 1) {
        if(!this.$route.params.id){
          this.url = 'b/boms/user/salesman/list'
        }
      }
      this.getSalesmen()
    }
  }
</script>
